CXX=g++
CC=gcc
CXXFLAGS=-std=c++11
TEST_EXEC=exec
TEST_SRC=test4.c
PLUGIN_SRC=directive-plugin.c
INCL=$(shell $(CC) -print-file-name=plugin)/include
LIBS=$(shell pwd)/lib

# mise à jour de la variable d'environnement pour que les libs soient trouvés à l'exécution
export LD_LIBRARY_PATH=$(LIBS)/:$LD_LIBRARY_PATH

all: bin/$(TEST_EXEC) 

complete: all run parse plot

.PHONY : all clean

# compiler la librairie runtime
lib/libruntime.so : src/lib-runtime.cpp src/lib-runtime.hpp
	$(CXX) -shared -fPIC -o $@ $< $(CXXFLAGS)

# compiler le plugin directive
lib/libdirective-plugin.so: src/$(PLUGIN_SRC) lib/libruntime.so
	$(CXX) -shared -fPIC -o $@ $< -lruntime -L$(LIBS) -I$(INCL)

# compiler le fichier test en faisant appel au plugin
bin/$(TEST_EXEC): lib/libdirective-plugin.so test/$(TEST_SRC) 
	$(CC) -fplugin=$^ -o $@ -lruntime -L$(LIBS) -O3 -fno-inline -fno-unroll-loops

run: $(EXEC)
	bin/$(TEST_EXEC)

parse: 
	make -C ./parser/

plot:
	make -C ./parser/plotter/ display
	
clean:
	rm -rf lib/* bin/* trace/*
	make -C ./parser/ clean
